package com.marry.business.service.active.impl;

import com.marry.business.entity.Active;
import com.marry.business.repository.active.ActiveRepository;
import com.marry.business.service.active.IActive;
import com.marry.contract.domain.User;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;
import java.util.List;

/**
 * @program: marry-cloud
 * @description: s
 * @author: 杨超
 * @create: 2021-08-16 10:58
 **/
public abstract class AbstractActive implements IActive {

    @Autowired
    ActiveRepository activeRepository;

    /**
     * 人数
     */
    protected List<User> ActivePartners;

    /**
     * 最大的人数
     */
    protected Integer MaxNum;




    @Override
    public List<User> getActivePartners() {
        return ActivePartners;
    }

    public void setActivePartners(List<User> activePartners) {
        ActivePartners = activePartners;
    }



    @Override
    public Integer getMaxNum() {
        return MaxNum;
    }

    public void setMaxNum(Integer maxNum) {
        MaxNum = maxNum;
    }

    /**
     * 添加一个活动人员
     * @param activePartner
     * @return
     */
    public  synchronized int addActivePartners(User activePartner) {
        this.ActivePartners.add(activePartner);
        return  this.getCurrentSize();
    }

    /**
     * 获取当前人数
     * @return
     */
    public Integer getCurrentSize(){
        return this.ActivePartners.size();
    }

    @Override
    public void activityStarted() {

    }


    @Override
    public void activityEnds() {

    }


    /**
     * 是否处于正在活动中
     * @return
     */
    @Override
    public Boolean isActiveExecue() {
        //获取当前时间
        Date nowDate = new Date();
        //如果开始时间大于当前时间，则活动不可能开启
        if(nowDate.compareTo(this.getStartTime())<0){
                return  false;
        }
        return null;
    }
}
